<style>

    #warpper .content{min-width:auto;}
    .integral_btn-group{width: 240px;}

</style>
<div id="warpper">
    <div class="content">
        <form action="" class="ui-form" method="post">
            <div class="form-box border0 border-box" style="border-top:1px solid #CCC !important;">

                    <table border="1" cellpadding="0" cellspacing="0" id="myTab">
                        <{foreach from=$data item=item}>
                        <tr>
                            <td width="50px" class="top-bt liebiao-c" align="center" ><input type="checkbox" class="check" name="ids[]" value="<{$item['id']}>" /></td>
                            <td width="40px" class="top-bt liebiao-c" align="center" ><input type="text" class="ui-text" name="names[]" value="<{$item['name']}>" /></td>
                        </tr>
                        <{/foreach}>
                    </table>
                    <input type="button" name="button" class="add-but" onclick="addNewRow();" value="添加类型" />

            </div>

            <div class="integral_btn-group">
                <input type="button" value="删除" onclick="removeRow();" class="ui-button fade-o-butn"/>
                <input type="submit" value="保存" class="ui-button"/>
            </div>
        </form>
    </div>
</div>

<script language="javascript">
    var eventsTypeAdd = "<{U('Events/eventsTypeAdd')}>";

    //提交form
    $("form").submit(function () {
            $(".check").each(function(){
                $(this).attr('checked',true);
            });
            $.getJSON(eventsTypeAdd,$(this).serialize(), function(data){
                if(data.status!=0){
                    layer.msg("数据获取失败，请稍后重试或联系管理员解决！");
                }else{
                    var d = data.eventsTypeData;
                    var str = '';
                    for( var i in d) {
                        str += '<option value="'+i+'">'+d[i]+'</option>';
                    }
                    $("#eventsType").html(str);
                    $(".ui-dialog-close").trigger('click');
                }
            });
            return false;
    });

    //窗口表格增加一行
    function addNewRow(){
        $("#myTab").append('<tr><td width="50px" class="top-bt liebiao-c" align="center" ><input type="checkbox" class="check" name="ids[]" value="0" /></td><td width="40px" class="top-bt liebiao-c" align="center" ><input type="text" class="ui-text" name="names[]" value="" /></td></tr>');
    }
    //窗口表格删除一行
    function removeRow(){
        $("#myTab tr").each(function(){
           if( $(this).find('.check').is(':checked') ){
               $(this).remove();
           }
        });
    }

</script>
</body>
</html>
